lobsterh5.main({
    data: {
        doctId: -1,
        deptId: -1,
    },
    pageload() {
        this.data.doctId = lobsterh5.GetUrlParam("doctId");
        this.data.deptId = lobsterh5.GetUrlParam("deptId");

        var self = this;
        self.initevent();
        self.getdoctorinfo();
        self.getevaluationinfo();

    },
    getdoctorinfo() {
        var param = {
            deptId: this.data.deptId,
            doctId: this.data.doctId
        };
        $.showLoading();
        lobsterh5.GETAPI("tsregister.doctorInfo", param).then(res => {
            console.log(res);
            // $(".weui-loadmore").hide();
            // this.data.empInfo = res.info;
            var html = template("tpldoctorinfo", res.info);
            $("#docinfo").html(html);
            // this.inittemp("tpldoctorinfo","docinfo",res.data);
            $.hideLoading();
        }).catch(res => {
            console.log(res);
        })

    },
    getevaluationinfo() {
        var self = this;
        lobsterh5.GETAPI('tsregister.getevaluationtopone', { doctId: this.data.doctId }).then(retdata => {
            if (retdata.data && retdata.data.length > 0) {
                self.inittemp("tplevaluation", "evaluationinfo", retdata.data);

                //全部评价
                $('#btnAllEvaluation').click(function () {
                    location.href = '/weuiapp/3225/evaluation/evaluatelist.html?doctId=' + self.data.doctId;
                });

                //点赞
                $('.btngivecount').click(function(){
                    var id = $(this).data("id");
                    $.showLoading();
                    lobsterh5.GETAPI('tsregister.updateevaluationgivecount',{id:id}).then(retdata=>{
                        $.hideLoading();
                        $.toast("点赞成功", 'text');
                        self.getevaluationinfo();
                    })
                });
            }
        }).catch(res => {
            $.toast(res.msg, 'text');
        })
    },
    initevent() {
        var self = this;
        //预约挂号
        $(document).on("click", ".toregister", function () {
            self.inittemp("tplrange", "half", []); //清空
            $("#half").popup();
            self.getdoctorrange(0);
        });
        //互联网问诊
        $(document).on("click", ".tointerrogation", function () {
            self.inittemp("tplrange", "half", []); //清空
            $("#half").popup();
            self.getdoctorrange(1);
        });

    },

    //显示排班时间段
    getdoctorrange(schedtype, callback) {
        var self = this;
        var param = {
            schedtype: schedtype,
            deptId: this.data.deptId,
            doctId: this.data.doctId
        };
        $.showLoading();
        lobsterh5.GETAPI("tsregister.dayTimeRange", param).then(res => {
            console.log(res);
            var list = res.list;

            self.inittemp("tplrange", "half", list);
            // $(".weui-loadmore").hide();
            $.hideLoading();

            //点击时段
            $(document).on("click", ".otc_timeview", function () {
                var info2 = $(this).data("info");
                if (info2.HaveCount > 0 && info2.Status == 0 && info2.IsExpire == 0) {
                    localStorage.setItem("registerrecord", JSON.stringify(info2));
                    var regtype = (schedtype == 0 ? 1 : 2);
                    location.href = "register/sure.html?appid=" + lobsterh5.GetAppId() + "&regtype=" + regtype;
                } else {
                    $.toast("无法操作", 'text');
                }
            });
            callback && callback();
        }).catch(res => {
            console.log(res);
            // $(".weui-loadmore").hide();
        })
    },

    inittemp(tempid, _id, data) {
        var html = template(tempid, { list: data });
        $("#" + _id).html(html);
    },
}, false); 